package cn.edu.swpu.cins.u_chain.frontend.controller.user;

import cn.edu.swpu.cins.u_chain.Exception.user.StudentException;
import cn.edu.swpu.cins.u_chain.Exception.user.TeacherException;
import cn.edu.swpu.cins.u_chain.frontend.entity.dto.ResultData;
import cn.edu.swpu.cins.u_chain.frontend.entity.dto.user.student.SkillList;
import cn.edu.swpu.cins.u_chain.frontend.entity.dto.user.student.StudentDetail;
import cn.edu.swpu.cins.u_chain.frontend.entity.dto.user.student.StudentInfo;
import cn.edu.swpu.cins.u_chain.frontend.entity.persistence.user.student.SkillInfo;
import cn.edu.swpu.cins.u_chain.frontend.service.user.StudentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.sql.SQLException;
import java.util.List;

@RestController
@RequestMapping("UChain/user/student")
public class StudentController {

    @Autowired
    private StudentService studentService;

    //@ExceptionHandler({StudentException.class, SQLException.class, RuntimeException.class})
    public ResultData handleException(Exception e) {
        return new ResultData(false, e.getMessage());
    }
    //学生添加个人信息
    @PostMapping("addInfo")
    public ResultData addStudentInfo(@RequestBody StudentInfo studentInfo) {
        studentService.addStudentInfo(studentInfo);
        return new ResultData(true, "信息添加成功");
    }

    @PostMapping("addSkills")
    public ResultData addSkills(@RequestBody List<SkillInfo> skillList) {
        studentService.addSkillLists(skillList);
        return new ResultData(true, "添加成功");
    }

    @GetMapping("getInfo")
    public ResultData getStudentInfo(@RequestParam int userId) {
        StudentDetail detail = studentService.selectDetail(userId);
        return new ResultData(true, "学生资料", detail);
    }

    @GetMapping("getSkills")
    public ResultData getStudentSkills(@RequestParam int userId) {
        SkillList skillList = studentService.selectSkills(userId);
        return new ResultData(true, "学生技能列表", skillList);
    }
}
